using Microsoft.AspNetCore.Hosting;
using Microsoft.AspNetCore.Server.Kestrel.Core;
using Microsoft.Extensions.Hosting;
using PublicGateway.Host;
using Serilog;
using Serilog.Events;
using SmartCity.Shared;

public class Program
{
    public static void Main(string[] args)
    {
        Log.Logger = new LoggerConfiguration()
            .MinimumLevel.Debug()
            .MinimumLevel.Override("Microsoft", LogEventLevel.Information)
            .MinimumLevel.Override("Microsoft.EntityFrameworkCore", LogEventLevel.Warning)
            .Enrich.WithProperty("Application", "CommonService")
            .Enrich.FromLogContext()
            .WriteTo.File("Logs/logs.txt", rollingInterval: RollingInterval.Day)
            .CreateLogger();
        CreateHostBuilder(args).Build().Run();
    }

    internal static IHostBuilder CreateHostBuilder(string[] args) =>
        Host.CreateDefaultBuilder(args)
            .ConfigureWebHostDefaults(webBuilder =>
            {
                var configuration = ConfigHelper.BuildConfiguration();
                webBuilder.UseStartup<Startup>();
                webBuilder.UseUrls(configuration["GlobalConfiguration:BaseUrl"]);
                webBuilder.UseKestrel(kestrel =>
                {
                    kestrel.ConfigureEndpointDefaults(options =>
                    {
                        options.Protocols = HttpProtocols.Http1AndHttp2;
                    });
                });
            })
            .UseAutofac();
}